package camid.util.dataanalysis;


public class JMeterMetric implements Comparable<JMeterMetric>{

	private JMeterTG tg;
	
	private Long timestamp;
	
	private Long responseTime;
	
	private boolean success;

	public JMeterTG getTg() {
		return tg;
	}

	public void setTg(JMeterTG tg) {
		this.tg = tg;
	}

	public Long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}

	public Long getResponseTime() {
		return responseTime;
	}

	public void setResponseTime(Long responseTime) {
		this.responseTime = responseTime;
	}
	
	public Boolean isSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	@Override
	public int compareTo(JMeterMetric o) {
		
		if( tg.compareTo(o.tg) != 0 )
		{
			return tg.compareTo(o.tg);
		}
		if( timestamp != o.timestamp )
		{
			return new Long(timestamp - o.timestamp).intValue();
		}
		if( responseTime != o.responseTime )
		{
			return new Long(responseTime - o.responseTime).intValue();
		}
		
		return 0;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((responseTime == null) ? 0 : responseTime.hashCode());
		result = prime * result + ((tg == null) ? 0 : tg.hashCode());
		result = prime * result
				+ ((timestamp == null) ? 0 : timestamp.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		JMeterMetric other = (JMeterMetric) obj;
		if (responseTime == null) {
			if (other.responseTime != null)
				return false;
		} else if (!responseTime.equals(other.responseTime))
			return false;
		if (tg == null) {
			if (other.tg != null)
				return false;
		} else if (!tg.equals(other.tg))
			return false;
		if (timestamp == null) {
			if (other.timestamp != null)
				return false;
		} else if (!timestamp.equals(other.timestamp))
			return false;
		if (success != other.success)
		{
			return false;
		}
		return true;
	}

	public String toCsvString() {
		String s = String.format("%d;%d;%d;%d;%b", this.tg.getNumberOfObjects(),
				this.tg.getDelay(), this.timestamp,this.responseTime,this.success);
		return s;
	}

	public String toString()
	{
		return toCsvString();
	}
	
}
